package cn.edu.neusoft.neufooddemo.activity;

import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.neufooddemo.R;
import cn.edu.neusoft.neufooddemo.adapter.OrderAdapter;
import cn.edu.neusoft.neufooddemo.bean.OrderInfo;
import cn.edu.neusoft.neufooddemo.listener.RetrofitListener;
import cn.edu.neusoft.neufooddemo.model.FoodModel;

public class MyOrderActivity extends BaseActivity implements RetrofitListener<List<OrderInfo>> {
    private RecyclerView myorder_rv;
    private ImageView myorder_return;
    private OrderAdapter adapter;
    private FoodModel foodModel;

    protected void initViews(){
        setLayout(R.layout.activity_myorder);
        myorder_rv = (RecyclerView)findViewById(R.id.myorder_rv);
        myorder_rv.setLayoutManager(new LinearLayoutManager(MyOrderActivity.this));
        myorder_return = (ImageView)findViewById(R.id.myorder_return);
    }

    void initEvents(){
        myorder_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    void initData(){
        foodModel = new FoodModel();
        foodModel.getAllUserOrder(getUser_id(),this);
    }

    @Override
    public void onSuccess(List<OrderInfo> orderInfos, int flag) {
        adapter = new OrderAdapter(MyOrderActivity.this, orderInfos, R.layout.cardview_order);
        myorder_rv.setAdapter(adapter);
    }

    @Override
    public void onFail() {
        showToast("网络错误");
    }
}
